//调用富文本textarea控件
var editor = new Simditor({
	textarea: $('#JoinCondition'),
	toolbar: false,
});
var editor2 = new Simditor({
	textarea: $('#ActivityContent'),
	toolbar: false,
});
var editor3 = new Simditor({
	textarea: $('#PrizeContent'),
	toolbar: false,
});
var editor4 = new Simditor({
	textarea: $('#ConvertWay'),
	toolbar: false,
});


//导入数据
function InputFrom(ActivityGetData){
	$(".input-theme").val(ActivityGetData.theme);
	$(".input-object").val(ActivityGetData.object);
	$(".input-date_start").val(format(ActivityGetData.dateStart));
	$(".input-date_end").val(format(ActivityGetData.dateEnd));
	$(".input-addr").val(ActivityGetData.addr);
	editor.setValue(ActivityGetData.criteria);
	editor2.setValue(ActivityGetData.content);
	editor3.setValue(ActivityGetData.prize);
	editor4.setValue(ActivityGetData.convertWay);
	$("#previewimg").html('<img src="'+ActivityGetData.picturePath+'"  class="PreviewPic"  style="display: block; width: 128px; height: 56px;">')

}

//时间戳转换为字符串
function add0(m){return m<10?'0'+m:m }
function format(TimeC)
{
var time = new Date(TimeC);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return add0(m)+'/'+add0(d)+'/'+y;
}  

//把表单改为只读
$('input,textarea').attr("readonly", true);
$('textarea').attr("style", "height:150px;");
$('select').attr("disabled", "disabled");
$('.simditor-body').attr("contenteditable", "false");
//初始化表单
init();
function init(){
	var GetDataURL=DataURL+"bank/activity/getActivityById";
	var ActivityPostData={};//通过ID请求活动数据
	var ActivityGetData={};//获得活动数据

	var Request = new Object();
	Request = GetRequest();
	$(".back-btn").click(function() {
		if(Request["back"]==1)
		{window.location.href=HostURL+"/activityManager/reviewActivity";}	
		else if(Request["back"]==3)
		{window.location.href=HostURL+"/activityManager/NotApprovalActivity";}
		else {window.location.href=HostURL+"/activityManager/bankActivity";}
	});
	function GetRequest() {
	    var url = location.search; //获取url中"?"符后的字串
	    var theRequest = new Object();
	    if (url.indexOf("?") != -1) {
	        var str = url.substr(1);
	        strs = str.split("&");
	        for(var i = 0; i < strs.length; i ++) {
	            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
	        }
	    }
	    return theRequest;
	}
	ActivityPostData["id"]=Request["id"];
	
	$.ajax({
		type : "GET",
		url : GetDataURL,
		dataType : 'json',
		async : false,
		data : ActivityPostData,
		success : function(data) {
			if(checkTokenError(data)){
			console.log(data.content.data.data);
			ActivityGetData = data.content.data.data;
			InputFrom(ActivityGetData);
			}
		},
        error:function(data){
            console.log(data)
            zxTips_short({
    			txt : "系统错误"
    			});
        }
	});
}